package com.zebra.gateway.session;

import com.zebra.remoting.connection.Connection;
import io.netty.channel.Channel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;


@Data
@ToString
@EqualsAndHashCode(of = {"userId"})
public class Session {

  private long userId;
  private long token;
  private Channel channel;

  private int gameId;  //gameId >0 表示在游戏， ==0 表示在大厅
  private Connection lobbyConn;
  private Connection gameConn;  //  当前 tms Connection
  private boolean isWeakClose = false; //true: 弱关闭, false: 表示在线;  如果断线则直接移除
  //用于切换服务器使用
  private int tempGid; // 临时 gameId
  private boolean tempExit = false; //临时  处理前端问题； 子游戏退出；自动 会在退出期间发消息；


  public Session(Channel channel) {
    this.channel = channel;
  }

  public boolean lobbyFine(){
    return null != this.lobbyConn && this.lobbyConn.isFine();
  }

  public boolean gameFine(){
    return null != this.gameConn && this.gameConn.isFine();
  }

  //true fine
  public boolean channelFine(){
    return  !isWeakClose && this.channel != null && this.channel.isActive();
  }


  public void setChannel(Channel channel){
    if (null != this.channel){
      ZebraAttribute.removeSession(this.channel);
    }
    this.channel = channel;
  }

}